{% comment %}
/* Copyright 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
{% endcomment %}
{% extends 'base.html' %}
{% block content %}
{% if action %}
  <div id="edit-message">
    {% if confirmation %}
    <div class="success">Update Completed!</div>
    {% else %}
    &nbsp;
    {% endif %}
  </div>
  <form method="POST">
    <input type="hidden" name="page" value="{{page.key}}">
    <input type="hidden" name="author" value="{{user.key}}">
    <table class="table-list">
      <tr>
        <td class="table-input-label">
          Title*:
          {% if warnings.title %}<br>
          <span class="warning">
            Title is required and shouldn't be too long (i.e.,< 500 bytes).
          </span>
          {% endif %}
        </td>
        <td class="table-input">
          <input
            class="text-input"
            type="text"
            name="title"
            value="{{page.title}}">
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          Button Name*:
          {% if warnings.button_name %}<br>
          <span class="warning">
          Button Name is required and should be as short as is useful.
          </span>
          {% endif %}
        </td>
        <td class="table-input">
          <input
            class="text-input"
            type="text"
            name="button_name"
            value="{{page.button_name}}">
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          Path:
          {% if warnings.path %}<br>
          <span class="warning">
          Path should be unique.
          </span>
          {% endif %}
        </td>
        <td class="table-input">
          <input
            class="text-input"
            type="text"
            name="path"
            value="{{page.path}}">
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          Canonical:
          {% if warnings.cannonical %}<br>
          <span class="warning">
          Cannonical shouldn't be too long (i.e., < 500 bytes).
          </span>
          {% endif %}
        </td>
        <td class="table-input">
          <input
            class="text-input"
            type="text"
            name="canonical"
            value="{{page.canonical_url}}">
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          Keywords:
          {% if warnings.keywords %}<br>
          <span class="warning">
          Keywords should be comma separated strings.
          </span>
          {% endif %}
        </td>
        <td class="table-input">
          <textarea
            class="textarea-small"
            name="keywords">{{page.keywords}}</textarea> (comma, separated,
          keywords)
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          Description:
          {% if warnings.description %}<br>
          <span class="warning">
          Description should be text only.
          </span>
          {% endif %}
        </td>
        <td class="table-input">
          <textarea
            class="textarea-med"
            name="description">{{page.description}}</textarea>
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          Body*:
          {% if warnings.body %}<br>
          <span class="warning">
          Body is required and should consist of only text.
          </span>
          {% endif %}
        </td>
        <td class="table-input">
          <textarea
            class="textarea-large"
            name="body">{{page.body}}</textarea>
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          NoIndex:
          {% if warnings.noindex %}<br>
          <span class="warning">
          Come on, it's a checkbox.
          </span>
          {% endif %}
        </td>
        <td class="table-input">
          <input
            type="checkbox"
            name="noindex"
            {% if page.noindex %}
            checked="true"
            {% endif %} >
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          NoFollow:
          {% if warnings.nofollow %}<br>
          <span class="warning">
          Come on it's a checkbox.
          </span>
          {% endif %}
        </td>
        <td class="table-input">
          <input
            type="checkbox"
            name="nofollow"
            {% if page.nofollow %}
            checked="true"
            {% endif %} >
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          NoArchive:
          {% if warnings.noarchive %}<br>
          <span class="warning">
          Come on it's a checkbox.
          </span>
          {% endif %}
        </td>
        <td class="table-input">
          <input
            type="checkbox"
            name="noarchive"
            {% if page.noarchive %}
            checked="true"
            {% endif %} >
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          NoSnippet:
          {% if warnings.nosnippet %}<br>
            <span class="warning">How do you mess up checking a box?</span>
          {% endif %}
        </td>
        <td class="table-input">
          <input type="checkbox" name="nosnippet" value="true"
            {% if page.nosnippet %} checked="true" {% endif %}>
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          NoODP:
          {% if warnings.noodp %}<br>
          <span class="warning">Your managed to mess up checking an unrequired
            checkbox. How'd you do that?</span>
          {% endif %}
        </td>
        <td>
          <input
            type="checkbox"
            class="warning"
            name="noodp"
            {% if page.noodp %}
            checked="true"
            {% endif %}
            value="true">
        </td>
      </tr>
      <tr>
        <td class="table-input-label">
          <b>Published:</b>
          {% if warnings.published %}<br>
          <span class="warning">
          Come on it's a checkbox.
          </span>
          {% endif %}
        </td>
        <td class="table-input">
          <input
            type="checkbox"
            name="is_published"
            {% if page.is_published %}
            checked="true"
            {% endif %} >
        </td>
      </tr>

      <tr>
        <td class="table-input-label">
          <input type="submit" name="save" value="Save">
        </td>
        <td class="table-input">
          <span class="required">* Required</span>
          <input type="submit" name="done" value="Done">
          <input type="submit" name="cone" value="Cancel">
        </td>
      </tr>
    </table>
  </form>
{% else %}
  <div id="new-page">
    <a href="/admin/pages?action=new">+ New Page</a>
  </div>
  <table class="table-list">
    <thead>
      <tr class="table-head">
        <td>Action</td>
        <td>Title</td>
        <td>Author - Created</td>
        <td>Author - Updated</td>
        <td>Published</td>
      </tr>
    </thead>
    <tbody>
    {% ifnotequal pages.count 0 %}
    {% for page in pages %}
      <tr>
        <td>
        <a href='/admin/pages?action=edit&page={{page.key}}'>Edit</a> |
        <a href='/admin/pages?action=delete&page={{page.key}}'>Delete</a>
        </td>
        <td>
        <a
        href="/{{page.button_name|cut:" "}}">
            {{page.title}}
        </a>
        </td>
        <td>
          {{page.author.nickname}} - {{page.draft_date|date:"Y/m/d"}}
        </td>
        <td>
          {{page.updated_by.nickname|default_if_none:"N/A"}} - {{page.edit_date|date:"Y/m/d"}}
        </td>
        <td>
          {% if page.is_published %}
            {{page.publish_date|date:"Y/m/d"}}
          {%else %}
            <span style="color:red">False</span>
          {% endif %}
        </td>
      </tr>
    {% endfor %}
    {% else %}
    <tr><td colspan="5">No pages have been created.</td></tr>
    {% endifnotequal %}
    </tbody>
  </table>
{% endif %}
{% endblock %}
